package com.dmpp.mes.service.impl;


import com.dmpp.mes.bean.RespEnum;
import com.dmpp.mes.bean.ResponseData;
import com.dmpp.mes.dao.AromaMapper;
import com.dmpp.mes.dao.MaterialTypeMapper;
import com.dmpp.mes.parameterInfo.Aroma;
import com.dmpp.mes.parameterInfo.MaterialType;
import com.dmpp.mes.service.AromaService;
import com.dmpp.mes.service.MaterialTypeService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service(value = "MaterialTypeService")

public class MaterialTypeServiceImpl implements MaterialTypeService {

    @Autowired
    private MaterialTypeMapper mapper;

    @Override
    public ResponseData findAll(MaterialType materialType) {
        ResponseData responseData = new ResponseData();
        PageInfo pageInfo = new PageInfo<>(mapper.findAll(materialType));
        responseData.setData(pageInfo);
        return responseData;
    }

    @Override
    public ResponseData findById(String id) {
        ResponseData responseData = new ResponseData();
        responseData.setData(mapper.findById(id));
        return responseData;
    }

    @Override
    public ResponseData insert(MaterialType materialType) {
        ResponseData responseData = new ResponseData();
        MaterialType materialType1= mapper.findById(materialType.getId());
        if (materialType1==null){
            mapper.insert(materialType);
        }else {
            responseData.setCodeEnum(RespEnum.ERROR2001);
        }
        return responseData;
    }

    @Override
    public ResponseData updateById(MaterialType materialType) {
        ResponseData responseData = new ResponseData();
        mapper.updateById(materialType);
        return responseData;
    }

    @Override
    public ResponseData delete(String code) {
        ResponseData responseData = new ResponseData();
        int number= mapper.count(code);
        if (number==0){
            mapper.delete(code);
        }else {
            responseData.setCodeEnum(RespEnum.ERROR1016);
        }
        return responseData;
    }

}
